package group2assignone.model;

import group2assignone.dao.MyDAO;
import group2assignone.ucm.UCStartup;

/**
 * Discounted Ticket is part of the Decorator pattern.  Adds a discount to
 * an original ticket.
 * @author group2
 */
public class DiscountedTicket extends Ticket {

    private Ticket ticket;
    private Flight f;
    private boolean booked = false;
    private static final int PERCENT = 100;

    /**
     * Constructor <br>
     * sets the ticket, and gets the flight.
     * @param ticket
     */
    public DiscountedTicket(Ticket ticket) {
        this.ticket = ticket;
        getFlight();
    }

    @Override
    public void getFlight() {
        MyDAO coms = UCStartup.getInstance().getDAO();
        f = coms.sQLGetFlight(ticket.getFlightNum());
    }

    @Override
    public double getCost() {
        double cost = 0;

        cost = Double.valueOf(f.getCost()) * f.getPromotion() / PERCENT;

        return cost;
    }

    @Override
    public double getGST() {
        double gst = getCost() * GSTax.getInstanceGSTax().getGST() / PERCENT;


        return gst;

    }

    @Override
    public double getAirportTax() {
        //Get departure location
        String depLoc = f.getDepLoc();
        MyDAO coms = UCStartup.getInstance().getDAO();
        double airportTax = getCost() * coms.sQLGetAirportTax(f.getDepLoc()) / PERCENT;
        return airportTax;
    }

    @Override
    public int bookTicket(int bookingNum, int itemNum) {
        System.out.println("Discounted Ticket booked for:" + ticket.getUsername() + ". Flight: " + ticket.getFlightNum());
        MyDAO coms = UCStartup.getInstance().getDAO();
        booked = coms.sQLMakeBooking(ticket, bookingNum, itemNum);
        itemNum = itemNum + 1;
        return itemNum;
    }

    @Override
    public boolean isBooked() {
        return booked;
    }
}
